package objects;

import java.util.Calendar;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class AlarmSet extends AlarmState {

	ScheduledThreadPoolExecutor timer = new ScheduledThreadPoolExecutor(1);

	@Override
	public AlarmState alarmOff() {
		timeSet = null;
		return alarmNotSet;
	}

	@Override
	public AlarmState alarmOn(Calendar time) {
		// We schedule alarmMakingNoise to the right time in the future.
		timeSet = time;
		// XXX: Debug
		// System.out.println("DEBUG: " + (timeSet.getTimeInMillis() -
		// Calendar.getInstance() .getTimeInMillis()));
		timer.schedule(alarmMakingNoise, timeSet.getTimeInMillis()
				- Calendar.getInstance().getTimeInMillis(),
				TimeUnit.MILLISECONDS);
		return alarmMakingNoise;
	}
}
